import { ApiTrack } from "./core";
import { ApiTrackConfig } from "./types";
import { collector } from "./plugins/collector";
import { teaReporter } from "./plugins/tea-reporter";
import { Reporter } from "./core/reporter";
export { axiosInterceptors } from "./utils/interceptors";

export * from "./core";
export * from "./types";

let apitrack: ApiTrack;

export function creatApiTrack({ slardar, customReporter, ...config }: ApiTrackConfig) {
  const reporter = new Reporter({
    slardar,
    biz_id: config.biz_id,
    env: config?.isOnline ? "online" : config.env || "other",
    options: customReporter,
  });
  apitrack = new ApiTrack({ ...config, reporter });
  apitrack.use(collector);
  apitrack.use(teaReporter);

  return apitrack;
}

export const track: typeof apitrack.track = (...args) => {
  return apitrack?.track?.(...args);
};
export const addRules: typeof apitrack.addRules = (...args) => {
  return apitrack?.addRules?.(...args);
};
// 设置业务上下文
export const setContext: typeof apitrack.setContext = (...args) => {
  return apitrack?.setContext?.(...args);
};
